package com.filetransfer.filedownloader.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.filetransfer.domain.FileInfo;

/**
 * This is the main object that holds a cached list of files
 * and their data while they are being downloaded. If exit is called,
 * the list of filesInProgress are rechecked for completion. 
 * if any file is completed then it is saved to the fileDir 
 * and corresponding entry in the filesInProgress is marked as downloaded.
 * (can easily add additional statistics such as time to download etc. finished time,
 * etc)
 *
 */
public class FileDownloadSession implements Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6452183321217856366L;
	
	
	private List<FileCache> fileCacheList = new ArrayList<FileCache>();
	
	
	/**
	 * 
	 */
	public final List<FileCache> getFileCacheList(){
		return fileCacheList;
	}
	
	/**
	 * 
	 * @param info
	 * @return
	 */
	public FileCache getFileCache(FileInfo info){
		FileCache cache = null;
		
		/*
		 * if it is a new file - create the file cache object with the required number
		 * of chunks 
		 * If it is an existing FileCache object- then return it.
		 */
		for(FileCache temp:fileCacheList){
			/*
			 * Compare the filename and return corresponding fileCache object.
			 */
			if(info != null && temp != null && temp.getFileName() != null && temp.getFileName().equalsIgnoreCase(info.getFileName())){
				cache = temp;
			}
		}
		return cache;
	}
	
	
	/**
	 * 
	 * @param cache
	 */
	public void setFileCache(FileCache cache){
		
	}
	
}
